package view;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import controller.FirewallSession;

/**
 * Logger table panel:
 * create table, defined scrollbar and label for the table
 */
public class LoggerPanel extends JPanel
{
	/**
	 * Serial version ID - for serialization
	 */
	private static final long serialVersionUID = -4929219520694617611L;
	
	/**
	 * C'tor - initiate the table according to table type.
	 * @param tableType - the type of the table (Global logger/FW logger)
	 * @param ui		- the controller for the system actions
	 */
	public LoggerPanel(FirewallSession UI, LoggerTableType tableType)
	{	
		setLayout(new BorderLayout());
		
		/*Table creation */
		AbstractLoggerTable table = null;
		
		switch(tableType)
		{
		case SESSIONS_TABLE:
			table = new LoggerTable(UI);
			break;
		case GLOBAL_TABLE:
			table = new LoggerGlobalTable(UI);
			break;
		}
		
		/* Label */
		JLabel label = new JLabel(table.getTableName() + ":");
		add(label, BorderLayout.NORTH);
	
		/* Header */
		add(table.getLoggerTableHeader(), BorderLayout.CENTER);
		table.getTableHeader().setReorderingAllowed(false);

		/* Table */
		JScrollPane scrollpane = new JScrollPane(table);
		scrollpane.getViewport().setPreferredSize(new Dimension(250,200));
		add(scrollpane,  BorderLayout.SOUTH);
	}
}
